﻿
Public Class frmprorderlist
    Dim Strsql As String
    Dim Mysql As New ClsSQLhelper
    Public SelectedOrder As String = ""

#Region "Function"
    Sub Load_Data(Optional ByVal PrOrder As String = "")

        Try
            Strsql = "select orderdate,ordernumber,site.site,orderedby,department.depname as depname,reason,orderstatus.orderstatus,yearbudget from prorder left join department on prorder.department = department.depcode left join site on prorder.site= site.siteid left join orderstatus on prorder.orderstatus= orderstatus.orderstatusid where orderstatus.statustype = 'pr' and prorder.orderstatus = 0"
            Dim DTProrder As New DataTable
            DTProrder = MySql.GetMYSQLDataTable(Strsql, "prorder")
            If DTProrder.Rows.Count = 0 Then
                Me.BtnOK.Enabled = False
                Exit Sub
            End If
            With Me.GridOrder
                .AllowUserToAddRows = False
                .AllowUserToDeleteRows = False
                .ReadOnly = True
                .DataSource = DTProrder

                .Columns("orderdate").HeaderText = "วันที่ขอ"
                .Columns("orderdate").DataPropertyName = "orderdate"
                .Columns("ordernumber").HeaderText = "เลขที่"
                .Columns("ordernumber").DataPropertyName = "ordernumber"
                .Columns("site").HeaderText = "คลังวัสดุ"
                .Columns("site").Width = 200
                .Columns("site").DataPropertyName = "site"
                .Columns("orderedby").HeaderText = "โดย"
                .Columns("depname").HeaderText = "แผนก"
                .Columns("depname").Width = 200
                .Columns("depname").DataPropertyName = "depname"
                .Columns("reason").HeaderText = "เหตุผล"
                .Columns("reason").DataPropertyName = "reason"
                .Columns("yearbudget").HeaderText = "ปีงบประมาณ"
                .Columns("yearbudget").DataPropertyName = "yearbudget"
                .Columns("orderstatus").HeaderText = "สถาณะ"
                .Columns("orderstatus").DataPropertyName = "orderstatus"
            End With


        Catch ex As Exception

        End Try

    End Sub
#End Region
    Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
        Me.Close()
    End Sub

    Private Sub frmprorderlist_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Load_Data()
    End Sub

    Private Sub BtnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnOK.Click

        Me.DialogResult = System.Windows.Forms.DialogResult.OK
        Me.Close()
    End Sub

    Private Sub GridOrder_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles GridOrder.CellClick
        With GridOrder
            SelectedOrder = GridOrder.Rows(.CurrentCell.RowIndex).Cells(1).Value
        End With
    End Sub

    Private Sub GridOrder_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles GridOrder.CellContentClick

    End Sub

    Private Sub GridOrder_CellDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles GridOrder.CellDoubleClick
        With GridOrder
            SelectedOrder = GridOrder.Rows(.CurrentCell.RowIndex).Cells(1).Value
        End With
        Me.DialogResult = System.Windows.Forms.DialogResult.OK
        Me.Close()
    End Sub
End Class